{extend name="common:base" /}

{block name="main"}
<div class="admin-content-body">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">留言管理</strong> / <small>Msg Management</small></div>
    </div>
    <ul class="am-avg-sm-1 am-avg-md-4 am-margin am-padding am-text-center admin-content-list ">
        <li><a href="{:url('admin/feedback/today')}" class="am-text-success">
            <span class="am-icon-btn am-icon-cart-plus"></span><br/>今日新增<br/></a></li>
        <li><a href="{:url('admin/feedback/week')}" class="am-text-danger">
            <span class="am-icon-btn am-icon-cart-arrow-down"></span><br/>一周以内<br/></a></li>
        <li><a href="{:url('admin/feedback/month')}" class="am-text-warning">
            <span class="am-icon-btn am-icon-bar-chart"></span><br/>一月以内<br/></a></li>
        <li><a href="{:url('admin/feedback/all')}" class="am-text-secondary">
            <span class="am-icon-btn am-icon-user-md"></span><br/>全部留言<br/></a></li>
    </ul>
    <div class="am-g">
        <div class="am-u-sm-12">
            <div class="am-panel am-panel-default">
                <div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-3'}">快速处理留言<span class="am-icon-chevron-down am-fr"></span></div>
                <div class="am-panel-bd am-collapse am-in am-cf" id="collapse-panel-3">
                    <ul class="am-comments-list admin-content-comment">
                        {volist name="list" id="vo"}
                        <li class="am-comment">
                            <a href="#"><img src="http://s.amazeui.org/media/i/demos/bw-2014-06-19.jpg?imageView/1/w/96/h/96" alt="" class="am-comment-avatar" width="48" height="48"></a>
                            <div class="am-comment-main">
                                <header class="am-comment-hd">
                                    <div class="am-comment-meta"><a href="#" class="am-comment-author">{$vo.user_id|get_username}</a> 留言于
                                        <time>{$vo.create_time}</time>
                                    </div>
                                </header>
                                <div class="am-comment-bd">
                                    <span>标题：{$vo.title}</span>
                                    <p>内容：{$vo.content}</p>
                                    <table>
                                        <tr height=22>
                                            <td class="reply" data-id="{$vo.feedback_id}" data-userod="$vo.user_id"><a 
                                                    href="javascript:void(0);">回复</a></td></tr>
                                        <tr height=4>
                                            <td></td>
                                        </tr>
                                    </table>
                                    <table id="child{$vo.id}" style="display: none">
                                        <tr>
                                            <td>
                                                <textarea name="reply" cols="50" rows="5"></textarea>
                                                <p><a href="#">提交</a></p>
                                            </td>
                                        </tr>
                                    </table>

                                </div>
                            </div>
                        </li>
                        {/volist}
                        {$list->render()}
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="am-popup" id="show-detail">
  <div class="am-popup-inner">
    <div class="am-popup-hd">
      <h4 class="am-popup-title"></h4>
      <span data-am-modal-close
            class="am-close">&times;</span>
    </div>
    <div class="am-popup-bd">
    </div>
  </div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
$('.reply').on('click',function(){
        var user_id = $(this).data('userid');
        $.get('{:url('admin/feedback/detailByAdmin')}?id='+$(this).data('id'),function(data){
            $('#show-detail').find('.am-popup-hd h4').html(data['title']);
            var str = '';
            str += '<p>留言内容:';
            str += data['content'];
            str +=  '</p>';
            for (var k = 0; k < data['reply'].length; k++) {
                if(data['reply'][k]['admin_id'] == 0){
                    str += '<p>';
                    str += data['reply'][k]['create_time'];
                    str += ':<span class="am-text-primary">';
                    str += data['reply'][k]['content'];
                    str +=  '</span></p>';
                }else{
                    str += '<p class="am-text-right"><span class="am-text-success">';
                    str += data['reply'][k]['content'];
                    str += '</span>:';
                    str += data['reply'][k]['create_time'];
                    str +=  '</p>';
                }
            }
            if (data['status'] == 1) {
                str += '<hr><form class="am-form" role="form" id="reply-form">\
                  <div class="am-form-group">\
                    <input type="hidden" class="am-form-field" name="feedback_id" value="'+data['feedback_id']+'">\
                    <textarea type="text" class="am-form-field" name="content" rows="3" placeholder="回复留言"></textarea>\
                  </div>\
                  <button type="submit" class="am-btn am-btn-default am-u-sm-3">回复</button>\
                  </div>\
                </form>';
            }else{
                str += '<span class="">已关闭</span>';
            }
            
            $('#show-detail').find('.am-popup-bd').empty();
            $('#show-detail').find('.am-popup-bd').append(str);
            $('#show-detail').modal();
        });
    });
$(document).on('submit','#reply-form',function(event){
        event.preventDefault();
        $.ajax({
            url: "{:url('admin/feedback/reply')}",
            type: 'POST',
            data: $('#reply-form').serialize(),
            success: function(data) {
                console.log(data);
                $alert = $('#am-alert');
                $alert.find('.content').text(data.msg);
                $alert.modal('open');
                if(data.code) {
                    setTimeout(function() {
                        location.href = data.url;
                    }, data.wait * 1000);
                } else {
                    $alert = $('#am-alert');
                    $alert.find('.content').text(data.msg);
                    $alert.modal('open');
                    $('#captcha-img').click();
                }
            },
            error:function() {
                $('#captcha-img').click();
                $alert = $('#am-alert');
                $alert.find('.content').text('系统错误，请重试');
                $alert.modal('open');
            }
        })
    });
</script>
{/block}